package com.kkb.kkbcommon.annotation.validation.validator;

import com.kkb.kkbcommon.annotation.validation.annotation.MultipartFilesNotEmpty;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @Author: 朱明亮
 * @Description: 多媒体文件不为空验证者
 * @Data Created in 2021-08-23 10:09:51
 * @Modified by:
 */
public class MultipartFilesNotEmptyValidator implements ConstraintValidator<MultipartFilesNotEmpty, MultipartFile[]> {

    /**
     * @Author: 朱明亮
     * @Description: 验证文件是否为空
     * @Data Created in 2021-08-23 10:17:07
     * @Modified by:
     */
    @Override
    public boolean isValid(MultipartFile[] value, ConstraintValidatorContext context) {
        if (value == null){
            return false;
        }
        for (MultipartFile multipartFile : value) {
            if (multipartFile.isEmpty()){
                return false;
            }
        }
        return true;
    }
}
